package com.treeroot.designMode.Strategy;


/**
 * @author treeroot
 */
public class Controller {
    /**
     * 创建一个商品对象和多个策略对象
     */
    public static void main(String[] args) {
        Goods goods = new Goods("手机", 200);
        //获取上下文---->策略的使用者--->构造函数传入策略对象
        DiscountContext context = new DiscountContext(goods, new EightDiscountStrategy());
        System.out.println("原价：" + goods.getPrice() + "元，打折后价格为：" + context.calculateDiscountPrice() + "元");
        //动态地切换算法---->set方法传入策略对象
        context.setStrategy(new FullMinusStrategy());
        System.out.println("原价：" + goods.getPrice() + "元，打折后价格为：" + context.calculateDiscountPrice() + "元");
    }
}
